home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / B-C / C++ FAQ Reference 1.0 / C++ FAQ Reference 1.0.rsrc / TEXT_1047.txt < prev    next >
Encoding:
Text File  |  1993-06-30  |  980 b   |  18 lines

  1. Private derivation can be thought of as a syntactic variant of containment (has-a).  Ex: it is NOT true that a privately derived is-a-kind-of-a Base:
  2.  
  3. With private derivation:
  4.     class Car : private Engine {/*...*/};    //a Car is NOT a-kind-of Engine
  5. Similarly:
  6.     class Car { Engine e; /*...*/ };    //normal containment
  7.  
  8. There are several similarities between these two forms of containment:
  9.  * in both cases there is exactly one Engine subobject contained in a Car
  10.  * in neither case can clients (outsiders) convert a Car* to an Engine*
  11.  
  12. There are also several distinctions:
  13.  * the second form is needed if you want to contain several subobjects
  14.  * the first form can introduce unnecessary multiple inheritance
  15.  * the first form allows members of Car to convert a Car* to an Engine*
  16.  * the first form allows access to the 'protected' members of the base class
  17.  
  18. Private inheritance is almost always used for the last item: to gain access into the 'protected:' members of the base class.